//
//  DawnGridView.swift
//  Test
//
//  Created by cuicheng on 2021/8/25.
//

import UIKit
import MJRefresh
class DawnGridView: ICBaseView {

    override func _initUI() {
        cv = {
            let v = UICollectionView(frame: .zero, collectionViewLayout: layout)
            return v
        }()
        addSubview(cv)
        adapter = DawnGridAdapter(cv)
    }
    
    func endRefresh() {
        if cv.mj_header?.isRefreshing == true {
            cv.mj_header?.endRefreshing()
        }
    }
    
    override func initFrame() {
        cv.inner(self, insets: insets)
    }
    

    var rowCount = 2
    {
        didSet {
            let itemWidth = (cv.frame.width - (layout.minimumInteritemSpacing * CGFloat(rowCount - 1))) / CGFloat(rowCount)
            if itemHeight == 0 { itemHeight = itemWidth }
            layout.itemSize = CGSize(width: itemWidth, height: itemHeight)
        }
    }
    var itemHeight: CGFloat = 0
    var insets = UIEdgeInsets.zero
    var adapter: DawnGridAdapter!
    lazy var layout: UICollectionViewFlowLayout = {
        let layout = UICollectionViewFlowLayout()
        layout.minimumInteritemSpacing = 0
        layout.minimumLineSpacing = 0
        return layout
    }()
    private var cv: UICollectionView!
}
